package Sort;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/26-上午9:45
 * Since  :   1.0
 * Version:   1.0
 */
public class SelectSort {

    public int[] select1(int arr[]) {

        for (int i = 0; i < arr.length - 1; i++) {
            int j = i;
            for (int index = j + 1; j < arr.length; j++) {
                if (arr[i] > arr[index]) {
                    int temp = arr[i];
                    arr[i] = arr[index];
                    arr[index] = temp;
                }
            }
        }
        return arr;
    }

    public static int[] select2(int arr[]) {
        for(int i=0;i<arr.length-1;i++){
            int minIndex=i;
            int minVal=arr[minIndex];
            for(int k=minIndex+1;k<arr.length;k++ ){
                if (arr[k]<minVal){
                    minIndex=k;
                    minVal=arr[k];
                }
            }
            if (minIndex!=i){

                arr[minIndex]=arr[i];
                arr[i]=minVal;
            }

        }
        return arr;
    }

}
